//获取应用实例
var app = getApp();

Page({
    onShow: function () {
        var that = this;
    },
    onLoad: function (e) {
        var that = this;
        that.setData({
            params: JSON.parse(e.data)
        });
        this.getOrderInfo()
    },
    createOrder: function (e) {
        app.showLoading();
        var that = this;
        var data = {
            type: this.data.params.type,
            note: '',
            goods: JSON.stringify(this.data.params.goods)
        };
        wx.request({
            url: app.buildUrl('/order/create/'),
            header: app.getRequestHeader(),
            method: 'POST',
            data: data,
            success: function (resp) {
                var data = resp.data;
                app.hideLoading();
                if (data.code == 200) {
                    wx.navigateTo({
                        url: "/pages/my/order_list"
                    });
                }
                else {
                    app.alert({"content": data.msg});
                }
            },
            fail: function () {
                app.hideLoading();
                app.alert({"content": "订单信息获取失败，请重试"});
            }
        });
    },
    addressSet: function () {
        wx.navigateTo({
            url: "/pages/my/addressSet"
        });
    },
    selectAddress: function () {
        wx.navigateTo({
            url: "/pages/my/addressList"
        });
    },
    getOrderInfo: function () {
        var that = this;
        var data = {
            type: this.data.params.type,
            goods: JSON.stringify(this.data.params.goods)
        };
        wx.request({
            url: app.buildUrl('/order/info/'),
            header: app.getRequestHeader(),
            method: 'POST',
            data: data,
            success: function (resp) {
                var data = resp.data;
                if (data.code == 200) {
                    that.setData({
                        goods_list: data.data.food_list,
                        default_address: data.data.address,
                        yun_price: data.data.yun_price,
                        pay_price: data.data.pay_price,
                        total_price: data.data.total_price
                    });
                }
                else {
                    app.alert({"content": data.msg});
                }
            },
            fail: function () {
                app.alert({"content": "订单信息获取失败，请重试"});
            }
        });
    }
});
